<?

//Data loading
$title='REPORT JOB ORDER PER PROJECT';
$curr = GetParam("curr","");

$perush = 'PT. AMPEL JAYA';

$page   = 'PAGE';
$TableName = "tbljoborder";
$DEFINE_FONT=0;
$pdf=new PDFReport("P","mm","Letter");
$pdf->AddPage();
$Result = ReportList ("", "", "");
if ($Result) $pdf->ReportTable($Result);
$pdf->Output();



function ReportList ($Space, $Index, $ParentID) {
	
	global $RS,$Index,$TableName,$curr;
	$DBConnection   = new mydb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
	if (!$Index) $Index = 0;


    $project_id = $_REQUEST['project_id'];

	$SQL = " SELECT * FROM ".$TableName." as a 		 
			 JOIN tblproject as b ON a.project_id = b.project_id  
			 JOIN tbldebtur as c ON a.debtur = c.CUDEBTUR
		   ";           

    if (GetParam("fromDate",""))
    {
        list($day1,$month1,$year1) = explode("/",GetParam("fromDate",""));
        $FDate = "$year1-$month1-$day1";
    }

    if (GetParam("toDate",""))
    {
        list($day2,$month2,$year2) = explode("/",GetParam("toDate",""));
        $TDate = "$year2-$month2-$day2";
    }


    if ($FDate)
        if (strlen($WHERE)) $WHERE .= " AND a.jo_date >= '".$FDate."' ";
        else $WHERE .= " a.jo_date >= '".$FDate."' ";

    if ($TDate)
        if (strlen($WHERE)) $WHERE .= " AND a.jo_date <= '".$TDate."' ";
        else $WHERE .= " a.jo_date <= '".$TDate."' ";
        
    if ($project_id)
        if (strlen($WHERE)) $WHERE .= " AND a.project_id = '".$project_id."' ";
        else $WHERE .= " a.project_id = '".$project_id."' ";    

  
    if (strlen($WHERE)) $WHERE = " WHERE ".$WHERE;
        else $WHERE = " WHERE 1 ";


    $SQL = $SQL.$WHERE;


    $SQL .= " ORDER BY a.jo_id DESC ";


    $MyResult = $DBConnection->dbc->get_results($SQL,ARRAY_A);
    
    return $MyResult;
    
}




class PDFReport extends PDF {

    function Header() {
        
        global $title,$perush,$page,$DEFINE_FONT,$curr;
        
        $project_name = $_REQUEST['project_name'];
         
        //Initial Date 
        $FDate = GetParam("fromDate","");		
		$TDate = GetParam("toDate","");		
		$SystemDate = date("d/m/Y");		
		//End Initial Date
        
        if ($DEFINE_FONT==0) {
            $this->AddFont('arialn','','arialn.php');
            $DEFINE_FONT=1;
        }
        $this->SetFont('arialn','',12);
		$this->Cell(195,5,$perush,0,1,'C',0);
		$this->Cell(195,5,$title,0,1,'C',0);
		
		$this->Cell(195,5,"REPORT FROM: ".GetParam("fromDate","")." TO: ".$TDate,0,1,'C',0);                
		$this->Cell(195,5,"PROJECT: ".$project_name,0,1,'C',0);
		$this->Cell(195,5,$page." ".$this->PageNo(),0,1,'R',0);
		$this->Line(10,30,205,30);
		$this->Ln();
		$this->Ln();
		//Header

		//Column widths               
		$w=array(35,30,55,30,30);
		$this->SetFont('arialn','',8);

		$this->Cell($w[0],7,"JOB ORDER",1,0,'C',0);
		$this->Cell($w[1],7,"DATE",1,0,'C',0);
		$this->Cell($w[2],7,"DEBTUR",1,0,'C',0);
		$this->Cell($w[3],7,"VESSEL",1,0,'C',0);
		$this->Cell($w[4],7,"STATUS",1,0,'C',0);

		$this->Ln();
    }

    function ReportTable($Result) {
        
        //echo "<pre>";
        //print_r($Result);
                  
        //Column widths
        $w=array(35,30,55,30,30);
        
        global $curr;
        
        //Data
        foreach($Result as $row)
        {

                $no++;
                                
                //Date Parse
                list($year,$month,$day) = explode("-",$row["jo_date"]);
                $FDate = "$day-$month-$year";                
                
                list($year2,$month2,$day2) = explode("-",$row["tglbkt"]);
                $FDate_2 = "$day2-$month2-$year2";                
                //End Date Parse
                                
                
                $this->Cell($w[0],6,$row["jo_code"],'LR',0,'C');
                                
                $this->Cell($w[1],6,$FDate,'LR',0,'C');
                
				$this->Cell($w[2],6,$row["CUNAME"],'LR',0,'C');					
                
                $this->Cell($w[3],6,$row["vessel"],'LR',0,'C');
                                                
                if($row["jo_appv_status"] == "draft")
                {                                    
                    $this->Cell($w[4],6,"Draft",'LR',0,'C');                   
                }
                
                else if($row["jo_appv_status"] == "wait_approved")
                {                                    
                    $this->Cell($w[4],6,"Wait For Approval",'LR',0,'C');                   
                }
                
                else if($row["jo_appv_status"] == "approved")
                {                                    
                    $this->Cell($w[4],6,"Approved",'LR',0,'C');                   
                }
                
                $this->Ln();
        }


        //Closure line
        //$this->Cell(array_sum($w),0,'','T');
    }

    function Footer() {
        //Closure line
        $this->Cell(180,0,'','T');
    }

}


?>
